package com.zzsoft.nettysocket.controller;/**
 * Created by zhanghb on 2019/9/8.
 */

import com.zzsoft.nettysocket.service.NettyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Description
 * @Author Zhanghb
 * @Date
 */
@Slf4j
@RestController
@RequestMapping("api/netty")
public class NettyController {
    @Autowired
    private NettyService nettyService;

    @RequestMapping(value = "msg", method = RequestMethod.GET)
    public Object sendMsg( String key, String msg,
                              HttpServletRequest request) throws IOException {
        log.info("开始发送数据");
        //nettyService.sedMsg(key,msg);
        nettyService.sendMsgToClient(key,msg);
        log.info("发送数据完成");
        return null;
    }

    @RequestMapping(value = "all", method = RequestMethod.GET)
    public Object sendMsgToAll( String msg,
                           HttpServletRequest request) throws IOException {
        log.info("开始发送数据");
        nettyService.sendMsgToAllClient(msg);
        log.info("发送数据完成");
        return null;
    }
}
